package com.tina.mapper;

import com.tina.entity.TiMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tina.entity.vo.TiMenuLeftVo;
import com.tina.entity.vo.TiMenuVo;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 菜单权限表 Mapper 接口
 * </p>
 *
 * @author PIGS
 * @since 2020-06-05
 */
@Repository
public interface TiMenuMapper extends BaseMapper<TiMenu> {

    /**
     * 级联查询父菜单
     *
     * @return
     */
    List<TiMenuVo> getAllMenus();

    /**
     * 级联查询子菜单
     *
     * @return
     */
    List<TiMenuVo> findMenuByParentId();

    /**
     * 通过角色ID
     * 查询菜单
     * @return
     */
    public List<TiMenuLeftVo> queryMenuLeftTreeByRoleId(Integer roleId);

    /**
     * 查询菜单数量
     *
     * @param parentId 菜单父ID
     * @return 结果
     */
    @Select("select count(1) from ti_menu where parent_id=#{menuId} and state!=2 ")
    public Integer queryCountMenuByParentId(Long parentId);

    /**
     * 通过菜单id
     * 查询上级菜单
     * 查询菜单权限
     *
     * @param menuId
     * @return
     */
    @Select("SELECT t.menu_id, t.parent_id, t.menu_name, t.order_num, t.url, t.target, t.menu_type,  t.perms, t.icon, t.remark, (SELECT menu_name FROM ti_menu WHERE menu_id = t.parent_id) parentName FROM ti_menu t where t.menu_id =#{menuId} ")
    public TiMenu queryMenuByMenuId(Long menuId);
}
